package com.banana.manager.forest.dao.handle;

import com.banana.manager.forest.entity.handle.AreaBean;
import com.banana.manager.forest.entity.handle.ClassBean;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface IAreaDao extends BaseMapper<AreaBean> {

    List<AreaBean> getAreaIncludeClass(@Param("areaName") String areaName,
                                       @Param("areaWoods")String areaWoods,
                                       @Param("className")String className);

    @Update("update area_info set fk_class_id = #{classId} where area_id = #{areaId}")
    @ResultMap("areaMap")
    void updateNewClass(@Param("classId") Integer classId, @Param("areaId") Integer areaId);

    @Select("select * from area_info Join class_info on " +
            "class_id = fk_class_id Where area_name like #{areaName} And class_name like #{className}")
    @ResultMap("areaMap")
    List<AreaBean> getClassByNameAndArea(@Param("areaName") String areaName,
                                       @Param("className")String className);

    @Select("Select * from area_info where fk_class_id is null")
    @ResultMap("areaMap")
    List<AreaBean> getNoClassAreaBean();

    @Select("Select * from area_info join class_info on class_id = fk_class_id where area_id = #{areaId}")
    @ResultMap("areaMap")
    AreaBean findOneIncludeClass(Integer areaId);

    @Select("select * from area_info left join class_info on class_id = fk_class_id")
    @ResultMap("areaMap")
    List<AreaBean> getAreaWithClass();

    @Select("select * from area_info left join class_info on class_id = fk_class_id where area_name=#{areaName}")
    @ResultMap("areaMap")
    AreaBean getClassByAreaName(String areaName);
}
